<?php


namespace app\admin\controller\mall;

use app\admin\model\MallGoods;
use app\admin\model\MallOrder;
use app\admin\model\MallTradeRecordLog;
use app\admin\model\MallUser;
use app\admin\model\MallWithdrawRecord;
use app\admin\model\SystemAdmin;
use app\api\help\SendMsg;
use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;
use think\facade\Db;
/**
 * @ControllerAnnotation(title="提现已驳回")
 */
class AuditStatus3 extends AdminController
{
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new MallWithdrawRecord();
    }
    
    /**
     * @NodeAnotation(title="已驳回")
     */
    public function cancel()
    {
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            [$page, $limit, $where] = $this->buildTableParames();
            $where[] = ['ea_mall_withdraw_record.status', '=', 10];
            $count   = $this->model
                ->withJoin(['user'], 'left')
                ->where($where)
                ->count();
            $list    = $this->model
                ->withJoin(['user'], 'left')
                ->where($where)
                ->page($page, $limit)
                ->order($this->sort)
                ->select()
                ->toArray();
            foreach ($list as $key => $value) {
                $list[ $key ][ 'id' ]       = $value[ 'user_id' ];
                $list[ $key ][ 'audit_id' ] = $value[ 'id' ];
            }
            $total  = $this->model
                ->withJoin(['user'], 'left')
                ->where($where)
                ->value('SUM(amount)');
            $newArr = ['type' => '', 'user' => ['name' => '总计', 'mobile' => ''], 'amount' => $total];
            array_unshift($list,$newArr);
            $data   = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }
}